package com.shuyun.xxx.guava.algorithm;

/**
 * Created by goodb on 2017/5/9.
 */
public class Practice {
    //求两个字符串最大的连续出现的公共部分 列如query为acbac，text为acaccbabb那么公共子串为cba 长度为3
    public static String publicStr(String query, String text){
        String max = query.length() > text.length() ? query : text;
        String min = max.equals(query) ? text : query;
        for(int i = 0; i < min.length(); i++){
            for(int start = 0, end = min.length() - i; end != min.length() + 1; start++, end++){
                String sub = min.substring(start, end);
                if(max.contains(sub)){
                    return sub;
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        String text = "abcdefg123456hijk";
        String query = "bcde12345abc";
        String common = publicStr(query, text);
        System.out.println(common + ", " + common.length());
    }
}
